home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 176-200 / 191 / filebootblock / filebootblock.asm < prev    next >
Assembly Source File  |  1995-03-13  |  10KB  |  315 lines

  1. **    Heres a little utility that I have just made.
  2. **    I thought what I wanted was on a fish disk but that program
  3. **    only saved dumps of boot blocks into files that disassemblers can
  4. **    read. So I decided to write one myself. Here it is
  5. **    The command to use on this is
  6. **    FileBootBlock df?: filename
  7. **    there must be only one space between the drive specifier of your
  8. **    filename will end up starting with spaces
  9. **    It will read the blocks 0 and 1 of the drive given and save it as
  10. **    a program file that can be run (heaven forbid) or disassembled
  11. **    by programs like DIS and DSM
  12. **    The only modifying it does is the the first 2 bytes of the block.
  13. **    As all program file must start with a valid instruction I have
  14. **    changed the first 2 bytes from 'DO' to $600A. This makes it into the
  15. **    instruction BRA.S *+$C which will get to the start of the proper code
  16.  
  17. **    Have fun
  18.  
  19. **    John Veldthuis
  20. **    21 Ngatai Street
  21. **    Manaia, Taranaki
  22. **    New Zealand
  23. **    22 November 1988
  24. **    Placed into the Public domain on this date
  25.  
  26.  
  27.    include  "exec/types.i"
  28.    include  "intuition/intuition.i"
  29.    include  "devices/trackdisk.i"
  30.    include  "exec/memory.i"
  31.    include  "libraries/dosextens.i"
  32.  
  33.    xref     _LVOOpenLibrary
  34.    xref     _LVOCloseLibrary
  35.    xref     _LVODoIO
  36.    xref     _LVOOpenDevice
  37.    xref     _LVOCloseDevice
  38.  
  39.    xref     _LVOAllocEntry
  40.    xref     _LVOFreeEntry
  41.    xref     _LVOOpen
  42.    xref     _LVOClose
  43.    xref     _LVOWrite
  44.    xref     _LVOAllocSignal
  45.    xref     _LVOFreeSignal
  46.  
  47. Offsets     macro
  48. \1          equ   soffset
  49. soffset     set   soffset+\2
  50.             endm
  51. soffset     set   0
  52.  
  53.             Offsets  dosbase,4
  54.             Offsets  execbase,4
  55.             Offsets  filehandle,4
  56.             Offsets  buffer,4
  57.             Offsets  port,4
  58.             Offsets  filename,4
  59.             Offsets  diskreq,4
  60.             Offsets  task,4
  61.             Offsets  mementry,4
  62.             Offsets  unit,4
  63.             Offsets  stdout,4
  64.  
  65.  
  66. Start:
  67.       lea      BASE(pc),a5
  68.       move.l   4,a6
  69.       move.l   a6,execbase(a5)
  70.       movem.l  d0/a0,-(sp)
  71.       move.l   $114(a6),a0           ;find our task
  72.       move.l   a0,task(a5)
  73.       move.l   pr_COS(a0),stdout(a5) ;save output stream for messages
  74.       moveq.l  #33,d0                ;version 33 or greater
  75.       lea      DosLib(pc),a1
  76.       jsr      _LVOOpenLibrary(a6)   ;open dos.library
  77.       movem.l  (sp)+,d1/a0
  78.       tst.l    d0
  79.       bne.s    Lib1
  80. NoLib move.l   #20,d0                ;no library, indicate error and stop
  81.       rts
  82. Lib1  move.l   d0,dosbase(a5)
  83.       moveq    #0,d0
  84.       move.b   d0,-1(a0,d1.w)        ;zero end of Command line
  85. 1$    move.b   (a0)+,d0
  86.       beq      CLIErr
  87.       and.b    #%11011111,d0         ;change to uppercase
  88.       cmp.b    #'D',d0               ;look for the D in DF?:
  89.       bne.s    1$
  90.       move.b   (a0)+,d0              ;dummy read to skip the F
  91.       move.b   (a0)+,d0              ;get unit number
  92.       sub.b    #'0',d0               ;make into a real number
  93.       ext.w    d0                    ;sign extend to a word
  94.       ext.l    d0                    ;sign extend to a long
  95.       move.l   d0,unit(a5)           ;save unit number
  96. 2$    move.b   (a0)+,d0              ;search for space
  97.       cmp.b    #' ',d0
  98.       bne.s    2$
  99.       move.l   a0,filename(a5)       ;save address of filename
  100.       lea      Mem(pc),a0
  101.       jsr      _LVOAllocEntry(a6)    ;allocate all memory in one go
  102.       btst     #31,d0
  103.       bne      MemErr                ;if bit 31 set then error getting mem
  104.       move.l   d0,mementry(a5)       ;save for release
  105.       move.l   d0,a0
  106.       add.w    #Mem1-Mem,a0
  107.       move.l   (a0),buffer(a5)       ;save address of read/write buffer
  108.       bsr      CreatePort            ;create a reply port
  109.       tst.l    d0
  110.       beq      PError                ;no message port
  111.       move.l   d0,d3
  112.       move.l   d0,port(a5)           ;save for closing later
  113.       move.l   mementry(a5),a0
  114.       add.w    #Mem2-Mem,a0
  115.       move.l   (a0),a0               ;make an IORequest block
  116.       move.b   #NT_MESSAGE,LN_TYPE(a0)
  117.       move.w   #IOSTD_SIZE,MN_LENGTH(a0)
  118.       move.l   d3,MN_REPLYPORT(a0)
  119.       move.l   a0,diskreq(a5)        ;save IO block address
  120.       move.l   unit(a5),d0
  121.       lea      TrackName(pc),a0
  122.       move.l   diskreq(a5),a1
  123.       moveq.l  #0,d1
  124.       jsr      _LVOOpenDevice(a6)    ;open trackdisk on unit
  125.       tst.l    d0
  126.       bgt      TErr                  ;won't open, display error
  127.       move.l   diskreq(a5),a1
  128.       move.w   #CMD_READ,IO_COMMAND(a1)
  129.       move.l   buffer(a5),IO_DATA(a1)
  130.       move.l   #1024,IO_LENGTH(a1)
  131.       move.l   #0,IO_OFFSET(a1)
  132.       jsr      _LVODoIO(a6)          ;read boot block into buffer
  133.       move.l   diskreq(a5),a1
  134.       move.w   #TD_MOTOR,IO_COMMAND(a1)
  135.       move.l   #0,IO_LENGTH(a1)
  136.       jsr      _LVODoIO(a6)          ;turn motor off
  137.       move.l   diskreq(a5),a1
  138.       move.b   IO_ERROR(a1),d3       ;see what error there was
  139.       jsr      _LVOCloseDevice(a6)   ;close trackdisk down
  140.       cmp.b    #19,d3
  141.       bgt      ReadErr               ;if an error display error
  142.       move.l   buffer(a5),a0
  143.       move.w   #$600A,(a0)           ;change first to bytes to BRA.S  *+$C
  144.                                      ;so as not to upset relative addresses
  145.       move.l   dosbase(a5),a6        ;get dosbase
  146.       move.l   filename(a5),d1
  147.       move.l   #MODE_NEWFILE,d2
  148.       jsr      _LVOOpen(a6)          ;open file that bootblock goes in
  149.       tst.l    d0
  150.       beq      OpenErr               ;didn't open for some reason
  151.       move.l   d0,filehandle(a5)     ;save for closing
  152.       lea      table(pc),a0          ;get first part of file
  153.       move.l   a0,d2                 ;used to create a program file
  154.       move.l   d0,d1                 ;filehandle into d1
  155.       moveq    #32,d3                ;length of numbers
  156.       jsr      _LVOWrite(a6)
  157.       cmp.l    #32,d0
  158.       bne      WriteErr
  159.       move.l   buffer(a5),d2
  160.       move.l   filehandle(a5),d1
  161.       move.l   #1024,d3
  162.       jsr      _LVOWrite(a6)         ;write out rest of block to file
  163.       cmp.l    #1024,d0              ;see if it all got written out
  164.       bne      WriteErr
  165.       move.l   filehandle(a5),d1
  166.       lea      hunkend(pc),a0
  167.       move.l   a0,d2
  168.       moveq    #4,d3
  169.       jsr      _LVOWrite(a6)         ;write last bit of file
  170.       cmp.l    #4,d0
  171.       bne.s    WriteErr
  172. Fin   move.l   filehandle(a5),d1
  173.       tst.l    d1
  174.       beq.s    1$
  175.       jsr      _LVOClose(a6)         ;close file if it opened
  176. 1$    move.l   execbase(a5),a6
  177.       move.l   port(a5),d0
  178.       tst.l    d0
  179.       beq.s    2$
  180.       move.l   d0,a1
  181.       bsr      DeletePort            ;delete port if one got made
  182. 2$    move.l   mementry(a5),d0
  183.       tst.l    d0
  184.       beq.s    3$
  185.       move.l   d0,a0
  186.       jsr      _LVOFreeEntry(a6)     ;freememory if any got allocated
  187. 3$    move.l   dosbase(a5),a1
  188.       jsr      _LVOCloseLibrary(a6)  ;close dos.library
  189.       rts
  190.  
  191.  
  192. MemErr:
  193.       lea      MemMess(pc),a0
  194.       move.l   a0,d2
  195.       moveq    #47,d3
  196.       bra.s    Err
  197. Error:
  198. CLIErr:
  199.       lea      CLIMess(pc),a0
  200.       move.l   a0,d2
  201.       moveq    #36,d3
  202.       bra.s    Err
  203. ReadErr:
  204.       lea      ReadMess(pc),a0
  205.       move.l   a0,d2
  206.       moveq    #36,d3
  207.       bra.s    Err
  208. WriteErr:
  209.       lea      WriteMess(pc),a0
  210.       move.l   a0,d2
  211.       moveq    #28,d3
  212.       bra.s    Err
  213. OpenErr:
  214.       lea      OpenMess(pc),a0
  215.       move.l   a0,d2
  216.       moveq    #25,d3
  217.       bra.s    Err
  218. PError:
  219.       lea      PMess(pc),a0
  220.       move.l   a0,d2
  221.       moveq    #41,d3
  222.       bra.s    Err
  223. TErr
  224.       lea      TMess(pc),a0
  225.       move.l   a0,d2
  226.       moveq    #39,d3
  227. Err   move.l   stdout(a5),d1
  228.       tst.l    d1
  229.       beq      Fin               ;if no output stream
  230.       move.l   dosbase(a5),a6
  231.       jsr      _LVOWrite(a6)
  232.       bra      Fin
  233.  
  234. CreatePort:
  235.       move.l   a2,-(a7)
  236.       move.l   mementry(a5),a2
  237.       add.w    #Mem3-Mem,a2
  238.       move.l   (a2),a2
  239.       moveq    #-1,d0
  240.       jsr      _LVOAllocSignal(a6)
  241.       moveq    #-1,d1
  242.       cmp.l    d0,d1   ;-1 indicates bad signal
  243.       bne.s    cp_sigok
  244.       move.l   (a7)+,a2
  245.       moveq    #0,d0        ;otherwise indicate no port
  246.       rts
  247. cp_sigok:
  248.       move.b   d0,MP_SIGBIT(a2)
  249.       move.b   #PA_SIGNAL,MP_FLAGS(a2)
  250.       move.b   #NT_MSGPORT,LN_TYPE(a2)
  251.       clr.b    LN_PRI(a2)
  252.       move.l   task(a5),d0
  253.       move.l   d0,MP_SIGTASK(a2)
  254.       lea.l    MP_MSGLIST(a2),a0  ;Point to list header
  255.       NEWLIST  a0      ;Init new list macro
  256.       move.l   a2,d0
  257.       move.l   (a7)+,a2   ;cc's NOT affected
  258.       rts
  259.  
  260. DeletePort:
  261.       moveq    #-1,d0
  262.       move.b   d0,LN_TYPE(a1)
  263.       move.l   d0,MP_MSGLIST+LH_HEAD(a1)
  264.       moveq    #0,d0
  265.       move.b   MP_SIGBIT(a1),d0
  266.       jsr      _LVOFreeSignal(a6)
  267.       rts
  268.  
  269. table:
  270.       dc.l     $3f3        ;Hunk_Header
  271.       dc.l     0           ;no Hunk_Name
  272.       dc.l     1           ;size of hunk table
  273.       dc.l     0           ;first hunk
  274.       dc.l     0           ;last hunk
  275.       dc.l     256         ;number of longwords in hunk
  276.       dc.l     $3e9        ;Hunk_Code
  277.       dc.l     256         ;number of longwords in hunk
  278.  
  279. hunkend
  280.       dc.l     $3f2        ;hunk end
  281.  
  282. BASE:
  283. Dosbase     dc.l  0
  284. Execbase    dc.l  0
  285. Filehandle  dc.l  0
  286. Buffer      dc.l  0
  287. Port        dc.l  0
  288. FileName    dc.l  0
  289. DiskReq     dc.l  0
  290. Task        dc.l  0
  291. MemEntry    dc.l  0
  292. Unit        dc.l  0
  293. Stdout      dc.l  0
  294.  
  295. Mem         ds.b  LN_SIZE
  296.             dc.w  3
  297. Mem1        dc.l  MEMF_CHIP!MEMF_CLEAR
  298.             dc.l  1024
  299. Mem2        dc.l  MEMF_PUBLIC!MEMF_CLEAR
  300.             dc.l  IOSTD_SIZE
  301. Mem3        dc.l  MEMF_PUBLIC!MEMF_CLEAR
  302.             dc.l  MP_SIZE
  303.  
  304. DosLib      dc.b  'dos.library',0
  305. TrackName   dc.b  'trackdisk.device',0
  306. MemMess     dc.b  'Not enough Memory to allocate required buffers',10
  307. CLIMess     dc.b  'Usage:  FileBootBlock df?: filename',10
  308. ReadMess    dc.b  'Disk Error while reading Boot Block',10
  309. WriteMess   dc.b  'Error while writing to file',10
  310. OpenMess    dc.b  'Error while opening file',10
  311. PMess       dc.b  'Couldn''t create message port for disk IO',10
  312. TMess       dc.b  'Couldn''t get access to specified drive',10
  313.  
  314.       end
  315.